package com.study.mike.controller;

import cn.hutool.core.util.ObjectUtil;
import com.study.mike.model.po.CatStatusPO;
import com.study.mike.model.po.QueryCatPO;
import com.study.mike.model.po.SaveOrUpKindCatPO;
import com.study.mike.result.R;
import com.study.mike.result.RUtil;
import com.study.mike.service.KindCatService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author KangHui
 * @Date 2022/11/4 16:08
 */
@RestController
@RequestMapping("/cat")
public class KindCatController {
    @Resource
    private KindCatService kindCatService;

    /**
     * saveOrUpdateCat
     *
     * @param po
     * @return
     */
    @PostMapping("/saveOrUpdate")
    public R saveOrUpdateCat(@RequestBody SaveOrUpKindCatPO po) {
        return RUtil.success(kindCatService.saveOrUpdateCat(po));
    }

    /**
     * 分页查询
     *
     * @param queryCatPO
     * @return
     */
    @PostMapping("/query")
    public R queryCat(@RequestBody QueryCatPO queryCatPO) {
        return RUtil.success(kindCatService.queryKindCat(queryCatPO));
    }

    /**
     * 移除数据
     *
     * @param po
     * @return
     */
    @PostMapping("/delete")
    public R deleteKindCat(@RequestBody SaveOrUpKindCatPO po) {
        if (ObjectUtil.isEmpty(po.getId())) {
            return RUtil.error("删除数据不能为空");
        }
        return RUtil.success(kindCatService.deleteKindCat(po.getId()));
    }

    /**
     * 状态设置
     *
     * @param po
     * @return
     */
    @PostMapping("/set/status")
    public R setKindCatStatus(@RequestBody CatStatusPO po) {
        if (ObjectUtil.isEmpty(po.getId())) {
            return RUtil.error("操作数据不能为空");
        }
        return RUtil.success(kindCatService.setKindCatStatus(po));
    }
}
